package com.quyunshuo.module.home.music

import com.quyunshuo.module.home.room.entity.MusicEntity

data class Music(
    val id: Long = 0,
    val title: String = "我的",
    val artist: String = "",
    val album: String = "",
    val duration: Long = 100, // 毫秒
    val path: String = "",
    val albumId: Long = 1
)

// 将 Music 转换为 MusicEntity
fun Music.toEntity(): MusicEntity {
    return MusicEntity(
        id = this.id,
        title = this.title,
        artist = this.artist,
        album = this.album,
        duration = this.duration,
        path = this.path,
        albumId = this.albumId,
        // 对于新音乐，设置创建时间为当前时间
        createdAt = System.currentTimeMillis(),
        // 播放记录初始化为0
        lastPlayed = 0,
        playCount = 0
    )
}

// 将 MusicEntity 转换回 Music
fun MusicEntity.toMusic(): Music {
    return Music(
        id = this.id,
        title = this.title,
        artist = this.artist,
        album = this.album,
        duration = this.duration,
        path = this.path,
        albumId = this.albumId
    )
}

// 将 List<MusicEntity> 转换为 List<Music>
fun List<MusicEntity>.toMusicList(): List<Music> {
    return this.map { it.toMusic() }
}